C#_C#算法函数:获取一个字符串中的最大长度的数字,/// summary/// 获取字符串
/// summary/// 获取字符串最长的数字/// /summary/// param输入字符串/param/// returns最长数字/returnspublic string GetMaxLenNumber(string inputStr){ //将字符串中的字符存放到数组中, maxLen); return s;} ,便于处理 char[] strCharArray = inputStr.ToCharArray(); //开始处理的位置 int startPos = 0; //当前处理的字符长度 int tempCharCount = 0; //数字的最长长度 int maxLen = 0; //数组的总长度 int len = strCharArray.Length; int pos = 0; while (startPos len) {//循环中的临时最大长度int tempMax = 0;while (tempCharCount + startPos len){//开始处理的字符char c = strCharArray[tempCharCount + startPos];if (char.IsNumber(c)){//如果是数字tempMax++;if (tempMax maxLen){maxLen = tempMax;pos = startPos;}}else{//不是数字tempMax = 0;startPos++;break;}tempCharCount++;}if (startPos + tempCharCount == len){break;}tempCharCount = 0;} string s = inputStr.Substring(pos,。
相关热词:
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/jiaob/c/9570.shtml
